﻿@using DirectSell.Model.User
@model IList<MemberLevel> 
@{
    ViewBag.Title = "RegisterIndex";
    Layout = "~/Areas/User/Views/Shared/UserLayout.cshtml";
}
    <main id="app-main" class="app-main">
        <div class="wrap">
            <section class="app-content">
                <div class="widget">
                    <header class="widget-header title2">
                        <h4 class="widget-title">会员注册</h4>
                    </header><!-- .widget-header -->
                    <hr class="widget-separator">
                    <div class="widget-body">
                    <form  id="form1"  class="form-horizontal">
                            <div class="form-group">
                                <label for="#"  class="col-sm-2 control-label">会员级别</label>
                                <div class="col-sm-5">
                                    @Html.DropDownList("database-dropdownlist", ViewBag.database as IEnumerable<SelectListItem>, new { @class = "form-control",@name= "UserLevel" })
                                </div><!-- END column -->
                            </div>

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">服务中心</label>
                                <div class="col-sm-5">
                                    <input class="form-control" type="text" required pattern="^[A-Za-z0-9]{4,40}$"
                                            title="服务中心请填写5-10位英文或数字" value="0001" name="ServiceCentreCode" 
                                           placeholder="请填您的服务中心">
                                </div>
                                <div class="col-sm-1 text-danger f-s1">5-10位英文或数字</div>
                            </div><!-- .form-group -->

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">新会员编号</label>
                                <div class="col-sm-5">
                                    <input class="form-control" required pattern="^[A-Za-z0-9]{4,40}$"  
                                           title="会员编号只能填写5-10位英文或数字"
                                           type="text" name="UserCode" value=@ViewBag.UserCode placeholder="请填写5-10位的英文数字">
                                </div>
                                <div class="col-sm-1 text-danger f-s1">5-10位英文或数字</div>
                            </div><!-- .form-group -->

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">推荐人编号</label>
                                <div class="col-sm-5">
                                    <input class="form-control" required pattern="^[A-Za-z0-9]{4,40}$" title="只能填写5-10位英文或数字"
                                               type="text" name="RefereeCode" placeholder="请填写您的推荐人编号" >
                                </div>
                                <div class="col-sm-1 text-danger f-s1">5-10位英文或数字</div>
                            </div><!-- .form-group -->

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">接点人编号</label>
                                <div class="col-sm-5">
                                    <input class="form-control" required pattern="^[A-Za-z0-9]{4,40}$" title="只能填写5-10位英文或数字"
                                           type="text" name="ContactCode" id="ContactCode" placeholder="请填写您的推荐人编号">
                                </div>
                                <div class="col-sm-1 text-danger f-s1">5-10位英文或数字</div>
                            </div><!-- .form-group -->
                        
                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">左右区</label>
                                <div class="col-sm-5">
                                    <select id="Area" name="Area" class="form-control" >
                                        <option value="1" selected="selected">左区</option>
                                        <option value="2">右区</option>
                                    </select>
                                </div>
                                <div class="col-sm-1 text-danger f-s1">注册区域</div>
                            </div><!-- .form-group -->


                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">真实姓名</label>
                                <div class="col-sm-5">
                                    <input class="form-control" required pattern="^[\u4E00-\u9FA5]{2,4}$" title="姓名只能由汉字组成"  
                                           type="text" value=@ViewBag.UserName name="UserName" placeholder="请填写您的中文名称">
                                </div>
                                <div class="col-sm-1 text-danger f-s"><span class="fa fa-asterisk"></span></div>
                            </div><!-- .form-group -->

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">身份证号</label>
                                <div class="col-sm-5">
                                    <input class="form-control" value=@ViewBag.IdNumber required  title="身份证格式不正确" 
                                            type="text" name="IdNumber" placeholder="请填写您的身份证号">
                                </div>
                                <div class="col-sm-1 text-danger f-s"><span class="fa fa-asterisk"></span></div>
                            </div><!-- .form-group -->

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">手机号码</label>
                                <div class="col-sm-5">
                                    <input class="form-control" value=@ViewBag.Phone  type="text" required  title="手机号格式不正确"
                                           name="Phone" placeholder="请填写您的手机号码">
                                </div>
                                <div class="col-sm-1 text-danger f-s"><span class="fa fa-asterisk"></span></div>
                            </div><!-- .form-group -->

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">登录密码</label>
                                <div class="col-sm-5">
                                    <input class="form-control" required  title="密码格式不正确"
                                            type="password"  name="UserPassWord" value="123456" placeholder="登录密码">
                                </div>
                                <div class="col-sm-1 text-danger f-s1">6-20数字字母组合(默认123456)</div>
                            </div><!-- .form-group -->

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">二级密码</label>
                                <div class="col-sm-5">
                                    <input class="form-control" required title="密码格式不正确"
                                            type="password" name="UserSecondPassWord" value="123456" placeholder="二级密码">
                                </div>
                                <div class="col-sm-1 text-danger f-s1">6-20数字字母组合(默认123456)</div>
                            </div><!-- .form-group -->

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">银行名称</label>
                                <div class="col-sm-5">
                                    <input class="form-control" required value=@ViewBag.BankName  name="BankName" placeholder="银行名称">
                                </div>
                                <div class="col-sm-1 text-danger f-s"><span class="fa fa-asterisk"></span></div>
                            </div><!-- .form-group -->

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">银行账号</label>
                                <div class="col-sm-5">
                                    <input class="form-control" value=@ViewBag.BankCode  required  name="BankCode" placeholder="银行账号">
                                </div>
                                <div class="col-sm-1 text-danger f-s"><span class="fa fa-asterisk"></span></div>
                            </div><!-- .form-group -->

                            <div class="form-group">
                                <label for="#" class="col-sm-2 control-label">持卡人姓名</label>
                                <div class="col-sm-5">
                                    <input class="form-control" required  value="@ViewBag.CardHolder" type="text" name="CardHolder" placeholder="持卡人姓名">
                                </div>
                            </div>
                        <!-- .form-group -->
                            @*<div class="clearfix">
                                <div class="table-responsive col-sm-7 col-sm-offset-1">
                                    <table class="table table-bordered table-striped">
                                        <tr class="danger color-f">
                                            <th>序号</th>
                                            <th>名称</th>
                                            <th>单位</th>
                                            <th>单价</th>
                                            <th>数量</th>
                                        </tr>
                                        <tr>
                                            <td>00001</td>
                                            <td>sdjlfsjdf</td>
                                            <td>个</td>
                                            <td>100</td>
                                            <td><input type="text" placeholder="0"></td>
                                        </tr>
                                    </table>
                                </div>
                            </div>*@

                            <div class="form-group m-t-xl">
                                <div class="col-sm-8 text-center">
                                    <button type="submit" class="btn btn-info">提交申请</button>
                                </div>
                            </div>
                            </form>
          </div><!-- .widget-body -->
                </div><!-- .widget -->
            </section><!-- #dash-content -->
        </div><!-- .wrap -->
        <!-- APP FOOTER -->
        <div class="wrap p-t-0">
            <footer class="app-footer">
                <div class="clearfix">
                    <div class="copyright text-center w100">@DirectSell.Common.Url.CommonConfig.companyName &copy;</div>
                </div>
            </footer>
        </div>
        <!-- /#app-footer -->
    </main>

<script type="text/javascript">
    $(function () {
        var code = GetQueryString();
        var area = GetArea();
        if (area == null) {
            area = 1;
        }
        $("#Area").val(area);

        $('#ContactCode').val(code);
    });
    $('#form1').on('submit', function(){
        formPost();
        event.preventDefault() //阻止form表单默认提交
    })
    function formPost() {
        //加载层
        var index = layer.load(1, {
            shade: [0.1, '#fff'] 
        });
        $.ajax({
            type: "post",
            url: "/User/Jurisdiction/Register",
            data: $('#form1').serialize(),
        }).success(function (message) {
            if (message != '成功') {
                layer.msg(message, { icon: 2 });
            }
            else {
                layer.msg('会员注册成功,是否前去激活？', {
                time: 0 //不自动关闭
                , btn: ['确定', '返回首页']
                , btn1: function (index) {
                location.href = "/User/Activation/Index";
                }, btn2: function (index) {
                location.href = "/User/Home/Index";
                }
                });
            }
        }).fail(function (err) {
            layer.msg('系统错误,请稍后重试', { icon: 2 });
        })
        layer.close(index)//关闭加载层
    }
    
    function GetQueryString()
    {
        var reg = new RegExp("(^|&)ConTactCode=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);//search,查询？后面的参数，并匹配正则
        if(r!=null)return  unescape(r[2]); return null;
    }

    function GetArea() {
        var reg = new RegExp("(^|&)Area=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);//search,查询？后面的参数，并匹配正则
        if (r != null) return unescape(r[2]); return null;
    }
</script>
